var mainh=null;

function goToLoginPage(){
  hideMainAFooter();
  var header=""
    +"<header id='mainheaderRegs' style='background:transparent;border:0;' >"
    +  "<a class='backButton left' ref='#login'>"
    +  "<img src='./img/first/returnlb.png' class='returnlbc' />"
    +  "</a>"
    +"</header>";
  $("#login").prepend(header);
  $("#mainheaderRegs").bind("click",function(){
    removeMainheaderRegs();
    showMainAFooter();
  });
}

function goToRegsPage(){
  removeMainheaderRegs();
  var header=""
    +"<header id='mainheaderRegs' style='background:black;'>"
    +  "<a class='backButton left' ref='#login'>"
    +  "<img src='./img/first/returnlb.png' class='returnlbc' />"
    +  "</a>"
    +  "<h1 class='labelp'>注册</h1>"
    +"</header>";
  $("#mainview").prepend(header);
  $("#mainheaderRegs").bind("click",function(){
    removeMainheaderRegs();
    goToLoginPage();
  });

}

/** for register page go to register personal panel
    this function removes the header created by register page and
    creater owner header
*/
function goToRegsPerPage(){
  removeMainheaderRegs();
  var header=""
    +"<header id='mainheaderRegs' style='background:black;' >"
    +  "<a class='backButton left' ref='#regs'>"
    +  "<img src='./img/first/returnlb.png' class='returnlbc'/>"
    +  "</a>"
    +  "<h1 class='labelp'>个人信息</h1>"
    +  "<div class='ingoreButton' id='ingoreDiv'>跳过</div>"
    +"</header>";
  $("#mainview").prepend(header);
  $("#mainheaderRegs").bind("click",function(){
    removeMainheaderRegs();
    goToRegsPage();
  });

  $("#ingoreDiv").bind("click",function(){
    $("#ingoreButton").click();
  });
}

/** for register personal page go to parking page*/
function goToParking(){
  removeMainheaderRegs();
  showMainAFooter();
}

/** go to comfirm order page **/
function goToComfirmOrder(){
  //window.location.hash='#comfirmparking';
  //$("#comfirmparking").addClass("active");
  hideMainAFooter();
  var header=""
    +"<header id='mainheaderRegs' style='background:black;' >"
    +  "<a class='backButton left' id='leftb' ref='#main'>"
    + "<img src='./img/first/returnlb.png' class='returnlbc'/>"
    +  "</a>"
    +  "<h1 class='labelp'>支付订单</h1>"
    +"</header>";
  $("#mainview").prepend(header);
  $("#leftb").bind("click",function(){
    removeMainheaderRegs();
    showMainAFooter();
  });
  /*
  setTimeout(function(){
    $("#comfirmparking").addClass("active");
  },510);
  */
  //$.afui.loadContent("#comfirmparking",false,false,"up");
}

function goToComfirmPayPage(){
  removeMainheaderRegs();
	 var header=""
		    +"<header id='mainheaderRegs' style='background:black;' >"
		    +  "<h1 class='labelp'>交易详情</h1>"
		    +"</header>";
	  $("#mainview").prepend(header);
  if(payPreId!="") {
	  try {
		//调用插件进行微信支付；
		  weixin.plugins.payPreId(payPreId);
	  }catch(e) {
		  payResultCall("false");
	  }
  }else {
	  payResultCall("false");
  }
  
}

function payResultCall(rs) {
	 removeMainheaderRegs();
	 var header=""
		    +"<header id='mainheaderRegs' style='background:black;' >"
		    +  "<h1 class='labelp'>交易详情</h1>"
		    +"</header>";
	  $("#mainview").prepend(header);
	  $("#comCost").html("￥"+$("#totalFee").val());
		  
     if(rs=='true') {
    	 $("#payResultImg").attr("src", "./img/messagesucc.png");
    	 $("#payResultContent").html("支付成功");
    	 //回传后台服务
    	 var telPhone=$("#username").html();
    	 $.getJSON(payOrderSuccessServer.returnPaySuccess("",payPreId,telPhone));
    	 payPreId = "";
     }else {
    	 $("#payResultImg").attr("src", "./img/messagefaild.png");
    	 $("#payResultContent").html("支付失败");
     }
    
}

function comPayGoBackMain(){
  removeMainheaderRegs();
  showMainAFooter();
  resetAll();
}

function removeMainheaderRegs(){
  $("#mainheaderRegs").remove();
}
function isShowSpacialCar() {
	var spacialCarSite=localStorage.getItem("spacialCarSite");
    if(spacialCarSite=="true"){
  	  var scs="<a id='specailMenu' class='specailMenu'>专属车位</a>";
  	  $("#mainheader").append(scs);
//  	  $("#tab1").css("color","black");
//  	  $("#tab1").html("停车缴费");
  	  $("#specailMenu").on('click',function(){
  		  $.afui.drawer.show("#topMenu","left","cover");
//  		  $("#tab1").css("color","black");
//      	  $("#tab1").html("停车缴费");
  	  });
//  	  $("#specailMenu").click();
  	  $("#tab1").on('click',function(){
  		  var spacialCarSite=localStorage.getItem("spacialCarSite");
  		  if(spacialCarSite){
      		  $.afui.drawer.hide("#topMenu","left");
      		  $("#tab1").html("我要停车");
      		  $("#tab1").css("color","#eeb71c");
//      		  $("#specailMenu").css("color","#ededed");
  		  }
  	  })
  	  
  	 $("#specailNumber").html(localStorage.getItem("parkNos"));
    }
}
